package com.example.mystoryapp2.data.sp

import android.app.Application
import android.content.SharedPreferences
import androidx.core.content.edit

object SpUtils {
    val USER_ID: String = "user_id"
    val JWT: String = "jwt"
    private lateinit var sp: SharedPreferences


    fun initUtils(app: Application) {
        sp = app.getSharedPreferences("data", 0);
    }

    fun setValue(key: String, value: Float) {
        sp.edit().putFloat(key, value).apply()
    }

    fun setValue(key: String, value: Int) {
        sp.edit().putInt(key, value).apply()
    }

    fun setValue(key: String, value: String) {
        sp.edit().putString(key, value).apply()
    }

    fun setValue(key: String, value: Long) {
        sp.edit().putLong(key, value).apply()
    }

    fun setValue(key: String, value: Boolean) {
        sp.edit().putBoolean(key, value).apply()
    }

    fun getStringValue(key: String): String? {
        return sp.getString(key, "")
    }

    fun getFloatValue(key: String): Float? {
        return sp.getFloat(key, 0f)
    }

    fun getBooleanValue(key: String): Boolean? {
        return sp.getBoolean(key, false)
    }

    fun getIntValue(key: String): Int? {
        return sp.getInt(key, 0)
    }

    fun getLongValue(key: String): Long? {
        return sp.getLong(key, 0L)
    }

    fun clearValue(key: String){
        sp.edit().remove(key)
    }

}